package com.xijia.wuyouwallet.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.xijia.wuyouwallet.MyApp;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.base.BaseActivity;
import com.xijia.wuyouwallet.utils.UrlConfig;

/**
 * Created by Administrator on 2017/7/18 0018.
 */

public class TradeBillActivity extends BaseActivity implements View.OnClickListener{

    private ImageView tradeBill_back;
    private ProgressBar tradeBill_progressBar;
    private WebView tradeBill_wv;
    private TextView tradeBill_type;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_trade_bill);
        initView();
    }

    private void initView(){
        tradeBill_back = (ImageView) findViewById(R.id.tradeBill_back);
        tradeBill_back.setOnClickListener(this);
        tradeBill_type = (TextView) findViewById(R.id.tradeBill_type);
        tradeBill_type.setOnClickListener(this);
        tradeBill_progressBar = (ProgressBar) findViewById(R.id.tradeBill_progressBar);
        tradeBill_wv = (WebView) findViewById(R.id.tradeBill_wv);

        tradeBill_wv.getSettings().setJavaScriptEnabled(true);
        //设置滚动条可见
        setProgressBarIndeterminateVisibility(true);
        init();
        tradeBill_wv.addJavascriptInterface(this, "getUser");
        tradeBill_wv.loadUrl(UrlConfig.TRADE_BILL_URL+"/id/"+MyApp.userData.getData().getUser_id());
    }

    private void init() {
        // TODO 自动生成的方法存根
        tradeBill_wv.setWebViewClient(new WebViewClient(){
            //覆写shouldOverrideUrlLoading实现内部显示网页
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO 自动生成的方法存根
                view.loadUrl(url);
                return true;
            }
        });
        tradeBill_wv.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // TODO 自动生成的方法存根
                tradeBill_progressBar.setProgress(newProgress);
                if (newProgress == 100) {
                    tradeBill_progressBar.setVisibility(View.GONE);
                }
                super.onProgressChanged(view, newProgress);
            }
        });
    }

    @JavascriptInterface
    public String getMsg(String str) {
        //Log.e("info","js号码="+str);
        //Intent intent = new Intent(Intent.ACTION_DIAL);
        //Uri data = Uri.parse("tel:" + str);
        //intent.setData(data);
        //startActivity(intent);
        return MyApp.userData.getData().getUser_id();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tradeBill_back:
                finish();
                break;
            case R.id.tradeBill_type:

                break;
        }
    }
}
